package cate.game.role.res.guild.po.treasurehouse;

import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
@NoteClass(value = "公会宝库物品时间数量信息")
public class GuildTreasureTimeItem {
    @NoteField("过期时间")
    private long expiredTimeStamp;
    @NoteField("组数")
    private int unitNum;

    /**
     * 获取组数
     */
    public int getUnitNum() {
        return checkExpired() ? 0 : unitNum;
    }

    /**
     * 获取原始组数
     */
    public int onGetOriginUnitNum() {
        return unitNum;
    }

    /**
     * 检测是否过期
     */
    public boolean checkExpired() {
        return System.currentTimeMillis() > expiredTimeStamp;
    }

    /**
     * 购买减少数量
     *
     * @param buyUnitNum 因购买减少的数量
     * @return 剩余数量
     */
    public int reduce(int buyUnitNum) {
        if (buyUnitNum >= this.unitNum) {
            int cost = this.unitNum;
            this.unitNum = 0;
            return buyUnitNum - cost;
        }
        this.unitNum -= buyUnitNum;
        return 0;
    }

    /**
     * 是否已耗尽
     */
    public boolean checkNumZero() {
        return this.unitNum == 0;
    }
}
